package cn.itsource.pet.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.SearchMasterMsg;
import cn.itsource.pet.domain.SearchMasterMsgDto;
import cn.itsource.pet.query.SearchMasterMsgQuery;
import cn.itsource.pet.service.ISearchMasterMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 寻主接单控制器
 */
@RestController
@RequestMapping("/searchmastermsg")
@Api(tags = "寻主接单管理", description = "寻主接单操作接口")
public class SearchMasterMsgController {

    @Autowired
    private ISearchMasterMsgService searchMasterMsgService;

    /**
     * 接单逻辑
     */
    @PostMapping("/jiedan")
    public AjaxResult jieDan(@RequestBody SearchMasterMsgDto msgDto){

        //接单
        searchMasterMsgService.jieDan(msgDto);

        return AjaxResult.createSuccess();
    }

    /**
     * 查询所有
     */
    @GetMapping
    @ApiOperation(value = "查询所有寻主接单信息", notes = "查询所有寻主接单信息，get请求")
    public List<SearchMasterMsg> findAll() {
        return searchMasterMsgService.findAll();
    }

    /**
     * 查询分页数据
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "查询部门分页数据", notes = "查询数据")
    public PageList<SearchMasterMsg> findPage(@RequestBody SearchMasterMsgQuery searchMasterMsgQuery) {

        //查询分页数据
        return searchMasterMsgService.findPage(searchMasterMsgQuery);
    }


    /**
     * 新增或修改的操作
     * 根据id来区分新增和修改
     * 怎么区分请求使用的请求方式  这里是post
     */
    @PostMapping
    public AjaxResult saveOrUpdate(@RequestBody SearchMasterMsg searchMasterMsg) {

        //没有id就是新增
        searchMasterMsgService.saveOrUpdate(searchMasterMsg);

        //返回成功对象
        return AjaxResult.createSuccess();
    }

    /**
     * 删除操作
     */
    @DeleteMapping("{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {

        searchMasterMsgService.delete(id);
        //返回成功对象
        return AjaxResult.createSuccess();

    }

}
